package keeto.com.vn.bms.ui.adapter;

import java.util.ArrayList;

import keeto.com.vn.bms.model.MedicalRecordModel;
import keeto.com.vn.bms.ui.activity.R;
import android.app.Activity;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

public class ListTypeScheduleAdapter extends BaseAdapter {
	private Activity mContext;
	public static ArrayList<MedicalRecordModel> typeSchedules;
	private LayoutInflater inflater;

	public ListTypeScheduleAdapter(Context context,
			ArrayList<MedicalRecordModel> typeSchedules) {
		// TODO Auto-generated constructor stub
		this.mContext = (Activity) context;
		this.typeSchedules = typeSchedules;
		this.inflater = LayoutInflater.from(mContext);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_row_table_record,
					parent, false);
			holder = new ViewHolder();
			holder.tvNameRecord = (TextView) convertView
					.findViewById(R.id.edt_adapter_record);
			holder.edtOperationCount = (EditText) convertView
					.findViewById(R.id.edt_hos_adapter_count);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.rowBotRecord = (View) convertView.findViewById(R.id.rowBot_hos);
		holder.tvNameRecord
				.setText(typeSchedules.get(position).getNameRecord());
		holder.edtOperationCount.setText(typeSchedules.get(position)
				.getOperatin_count());
		holder.rowBotRecord = (View) convertView
				.findViewById(R.id.rowBotRecord);
		if (typeSchedules.get(position).getOperatin_count().equals("")
				|| typeSchedules.get(position).getOperatin_count().equals("0")) {
			holder.edtOperationCount
					.setBackgroundResource(R.drawable.bg_popup_null);
			holder.edtOperationCount.setHint(mContext.getResources().getString(
					R.string.import_count_schedule));

		} else {
			holder.edtOperationCount.setText(typeSchedules.get(position)
					.getOperatin_count());
		}

		holder.edtOperationCount
				.setOnFocusChangeListener(new OnFocusChangeListener() {

					@Override
					public void onFocusChange(View v, boolean hasFocus) {
						// TODO Auto-generated method stub

						holder.edtOperationCount.setHint("");

					}
				});
		holder.edtOperationCount.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				// TODO Auto-generated method stub
				typeSchedules.get(position).setOperatin_count(s.toString());
			}
		});
		return convertView;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return typeSchedules.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return typeSchedules.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	class ViewHolder {
		TextView tvNameRecord;
		EditText edtOperationCount;
		View rowBotRecord;
	}
}
